package com.aeoj.clientmanagement.enums.room;

import lombok.Getter;

/**
 * 题目状态枚举
 * author: ZSM
 * time: 2025-04-21 16:44
 */
@Getter
public enum RoomQuestionStatusEnum {
    /**
     * 正常状态
     */
    NORMAL(0, "正常"),

    /**
     * 未启用状态
     */
    DISABLED(1, "未启用");

    private final Integer code;
    private final String description;

    RoomQuestionStatusEnum(Integer code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 根据code获取枚举
     * @param code 状态码
     * @return 对应的枚举，找不到返回null
     */
    public static RoomQuestionStatusEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (RoomQuestionStatusEnum status : RoomQuestionStatusEnum.values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }

    /**
     * 检查code是否有效
     * @param code 状态码
     * @return 是否有效
     */
    public static boolean isValid(Integer code) {
        return getByCode(code) != null;
    }

    /**
     * 判断题目是否正常状态
     * @param code 状态码
     * @return 是否正常状态
     */
    public static boolean isNormal(Integer code) {
        return NORMAL.getCode().equals(code);
    }

    /**
     * 判断题目是否未启用状态
     * @param code 状态码
     * @return 是否未启用状态
     */
    public static boolean isDisabled(Integer code) {
        return DISABLED.getCode().equals(code);
    }
}
